/**
 * 136. 只出现一次的数字
 * https://leetcode-cn.com/problems/single-number/
 */

/**
 * @param {number[]} nums
 * @return {number}
 */
function singleNumber(nums) {
  let sign = 0;
  for (let i = 0; i < nums.length; i += 1) {
    sign ^= nums[i];
  }
  return sign;
}

console.log(singleNumber([2, 2, 1]) === 1);
console.log(singleNumber([4, 1, 2, 1, 2]) === 4);
